package com.waiter.moximoxi.app;

import android.content.Context;
import android.support.multidex.MultiDex;

import com.iflytek.cloud.SpeechUtility;
import com.waiter.moximoxi.juph.JPushUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.https.HttpsUtils;

import java.net.Proxy;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.Collections;
import java.util.concurrent.TimeUnit;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import cn.yhong.aframework.app.AfApplication;
import cn.yhong.aframework.utils.JsonUtils;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;

/**
 * Created by 17639 on 2020/10/14.
 */

public class MyApplication extends AfApplication {

    @Override
    public void initApplication() {

        //初始化极光推送
        JPushUtils.getInstance().init(this, false);

        // 分包
        MultiDex.install(this);
        // 初始化json解析
        JsonUtils.init("code", "msg", "data");

//        https://www.jianshu.com/p/64cc92c52650 https证书问题
        //设置可访问所有的https网站
        HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory(null, null, null);

        //初始化OkHttpUtils
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .connectTimeout(10000L, TimeUnit.MILLISECONDS)
                .readTimeout(10000L, TimeUnit.MILLISECONDS)
                .sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
                .protocols(Collections.singletonList(Protocol.HTTP_1_1))
                .retryOnConnectionFailure(true)
                .proxy(Proxy.NO_PROXY)//不使用代理的模式
                //其他配置
                .build();
        OkHttpUtils.initClient(okHttpClient);

        //初始化讯飞语音
        SpeechUtility.createUtility(this, "appid=736c1846");
    }


    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        // 分包
        MultiDex.install(base);
    }
}
